# -*- coding:utf-8 -*-
# @Time  : 2019/11/27 16:10
# @Author: wangxb
import datetime
import os
import subprocess
import time


def run_tinytask(rec_file_compiled):
    # 运行外部脚本，传入参数和接受print内容
    # p = subprocess.Popen(['python','xxx.py','-n',sth_to_pass],stdout=subprocess.PIPE)
    # result = p.stdout.read()

    # 参考pytesseract.py
    command = [rec_file_compiled]
    # proc = subprocess.Popen(command, stderr=subprocess.PIPE)
    proc = subprocess.Popen(command)
    status = proc.wait()
    # error_string = proc.stderr.read()
    # proc.stderr.close()
    # print status, error_string
    return status


def main():
    rec_file_compiled = 'G:/pydata/install/test.exe'  # tinytask导出的编译文件
    print(run_tinytask(rec_file_compiled))
    print('finished')


def hasNumbers(inputString):
    return any(char.isdigit() for char in inputString)


def traverseDocument(searchRootPath):
    '''
    获取目录下的文件
    :return:
    '''
    apkList = []
    if os.path.exists(searchRootPath):
        for root, dirs, files in os.walk(searchRootPath, topdown=False):
            for name in files:
                # print(os.path.join(root, name))
                print(name)
                apkList.append(name)
    return apkList


if __name__ == '__main__':
    # main()
    # starttime = datetime.datetime.now()
    # # long running
    # # do something other
    # endtime = datetime.datetime.now()
    # print(endtime - starttime).seconds
    # print(hasNumbers("sssd"))
    # print(hasNumbers("sssd3sss4"))
    listt = traverseDocument("D:\Work\Python\GetWeChatID\APKSources")
    for filename in listt:
        print(filename)
